<?php
/**
 * Aero - Xistins Technologies PHP Framework
 * 
 * LICENSE
 * This source file is subject to the New BSD license that is bundled 
 * with this package in the LICENSE.txt. It is also available through 
 * the world-wide-web at this URL: http://dev.xistins.com/license/production
 * If you did not receive a copy of this license and are unable to obtain
 * it through the world-wide-web, please send an email to 
 * license@xistins.com so we can send you a copy immediately.
 * 
 * @category   Aero
 * @package    Aero_View
 * @subpackage Helper
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: HeadCss.php 2 2009-11-03 04:10:03Z csouth@xistins.com $
 */

/** @see Aero_View_Helper **/
require_once 'Aero/View/Helper.php';

/**
 * View helper for CSS links
 * 
 * @category   Aero
 * @package    Aero_View
 * @subpackage Helper
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: HeadCss.php 2 2009-11-03 04:10:03Z csouth@xistins.com $
 */
class Aero_View_Helper_HeadCss extends Aero_View_Helper
{
    /**
     * Stylesheets as array
     * @var array
     */
    protected $_styleSheets = array();

    /**
     * Add or get CSS file to stack
     * 
     * @param  string $location
     * @param  string $media
     * @param  string|bool $if
     * @param  bool $prepend
     * @return Aero_View_Helper_HeadCss
     */
    public function headCss($location = '', $media = 'screen', $if = NULL, $prepend = false)
    {
        if($location != '') {
            $stylesheet = array('location' => $location,
                                'media'    => $media,
                                'if'       => $if);
    
            if($prepend) {
                array_unshift($this->_styleSheets, $stylesheet);
            } else {
                $this->_styleSheets[] = $stylesheet;
            }
        }

        return $this;
    }

    /**
     * Return css links as string
     * 
     * @return string
     */
    public function __toString()
    {
        $retVal = '';

        foreach($this->_styleSheets as $stylesheet) {
            $location = $stylesheet['location'];
            $media    = $stylesheet['media'];
            $if       = $stylesheet['if'];

            if(null !== $if) {
                $retVal .= $this->_indent;
                $retVal .= "<!--[if $if]>\n";
            }

            $retVal  .= $this->_indent;
            $retVal  .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$location\" media=\"$media\" />\n";

            if(null !== $if) {
                $retVal .= $this->_indent;
                $retVal .= "<![endif]-->\n";
            }
        }

        return $retVal;
    }
}